package com.huaru.message.xiancheng.B;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class ReentrantLockDemo implements Runnable{
    private int nike = 10;
    Lock reetrantLock = new ReentrantLock();
    @Override
    public void run() {
        while (true){
            reetrantLock.lock();
            try {
                if(nike >0){
                    Thread.sleep(1000);
                    System.out.println(Thread.currentThread().getName() + "抢到了第" + nike-- + "双鞋");
                }
            }catch (InterruptedException e){
                e.printStackTrace();
            }finally {
                reetrantLock.unlock();
            }

        }
    }
}
